package com.kira.scaffoldmvc.Test;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Optional;

public class Main1 {
    public static void main(String[] args) {
        // 模拟获取原始请求头（这里只是示例，实际可能从其他地方获取）
        java.util.Map<String, String> originalHeaders = java.util.Map.of("Authorization", "storeIt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IjE2NTcyOTQwMzJAcXEuY29tIiwiYWNjb3VudElkIjoiNjdiMDk5ZjI3Y2NjMTE0" +
                "ZjgwNzQ1MWY0IiwiaWF0IjoxNzQwMDQxMTg3LCJleHAiOjE3NDAxMjc1ODd9.UYt1UYnEk-r1yAs44N_yHtYLvneN6QgHWxSLh5R2_Kw");

        // 获取Authorization头信息
        String authorizationHeader = originalHeaders.getOrDefault("Authorization",null);

        try {
            // 创建HttpClient实例
            HttpClient client = HttpClient.newHttpClient();

            // 创建HttpRequest实例，设置请求URL和请求方式
            HttpRequest request = HttpRequest.newBuilder()
                   .uri(URI.create("http://47.119.148.251:7000/user/userInfo"))
                   .header("Authorization", authorizationHeader)
                   .GET()
                   .build();

            // 发送请求并获取响应
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

            // 处理响应
            System.out.println("响应状态码: " + response.statusCode());
            System.out.println("响应体内容: " + response.body());
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}